<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        var str = "今天的天气真不错啊!";
        var sum = '';
        for (var i = 0; i < str.length; i++) {
            //if(str.charAt(i) == '天' && str.charAt(i+1) == '气'){
            if (str.charAt(i) + str.charAt(i + 1) == '天气') {
                sum += '*';
                i++;//跳过“气”的判断
            } else {
                sum += str.charAt(i);
            }
        }
        console.log(sum);
    </script>
</body>

</html>